package leetcode.code0816;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	List<String> ans;

	public List<String> ambiguousCoordinates(String s) {
		ans = new ArrayList<>();
		s = s.substring(1, s.length() - 1);
		// 逗号
		for (int i = 1; i < s.length(); i++) {
			this.f(s.substring(0, i), s.substring(i));
		}
		return ans;
	}

	private void f(String s1, String s2) {
		// s1的点
		for (int i = 1; i <= s1.length(); i++) {
			String a = this.ff(s1.substring(0, i), s1.substring(i));
			if (a != null) {
				// s2的点
				for (int j = 1; j <= s2.length(); j++) {
					String b = this.ff(s2.substring(0, j), s2.substring(j));
					if (b != null) {
						ans.add(this.str(a, b));
					}
				}
			}
		}
	}

	private String ff(String s1, String s2) {
		if (this.c1(s1)) {// s1 不是数
			return null;
		}
		if (s2.equals("")) {// s2 不是数
			return s1;
		}
		if (Integer.valueOf(s1) == Integer.valueOf(s2) && Integer.valueOf(s1) == 0) {// 0.0
			return null;
		}
		if (this.c2(s2)) {// s2 不是数
			return null;
		}
		return s1 + '.' + s2;
	}

	private boolean c2(String s) {
		int num = Integer.valueOf(s);
		if (num == 0) {
			return true;
		}
		int len = s.length();
		if (len == 1) {
			return false;
		}
		int n = Integer.valueOf(s.substring(s.length() - 1));
		if (0 == n) {
			return true;
		}
		return false;
	}

	private boolean c1(String s) {
		int len = s.length();
		if (len == 1) {
			return false;
		}
		if (Integer.valueOf(s) < Math.pow(10, len - 1)) {
			return true;
		}
		return false;
	}

	private String str(String n1, String n2) {
		StringBuffer sb = new StringBuffer();
		sb.append('(').append(n1).append(", ").append(n2).append(')');
		return sb.toString();
	}

	@Override
	public void debug4() {
		H.compare(H.str2liststr("[\"(0.01, 0)\"]"), this.ambiguousCoordinates("(0010)"));
//		H.compare(H.str2liststr("[\"(1, 23)\", \"(12, 3)\", \"(1.2, 3)\", \"(1, 2.3)\"]"), this.ambiguousCoordinates("(123)"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
		String a = "1234";
		System.out.println(a.substring(a.length()).equals(""));
	}

}
